package cn.gov.cus.rmftquartz.aspect;

import cn.gov.cus.rmftquartz.annotation.Log;
import cn.gov.cus.rmftquartz.common.utils.HGLogHelper;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 面向切面AOP
 * 注解@Aspect和@Pointcut都是aspectjweaver-1.8.10.jar!\org\aspectj\lang\annotation下的。
 * @author wxming.
 * @date 2018/3/15.
 */
@Aspect
@Component
public class ParaAspect {
    @Resource
    private HGLogHelper logHelper;

    @Pointcut(value = "@annotation(cn.gov.cus.rmftquartz.annotation.Log)")
    public void paraLog(){}

    @AfterReturning(value ="paraLog()",returning = "result")
    public void pringLog(JoinPoint joinPoint,Object result){
        MethodSignature methodSignature = (MethodSignature)joinPoint.getSignature();
        Log clzAnt = joinPoint.getTarget().getClass().getAnnotation(Log.class);
        Log methodAnt = methodSignature.getMethod().getAnnotation(Log.class);
        String modelName = clzAnt.modelName();
        String operateNote = methodAnt.operateNote();
        logHelper.byIOBusinessLog(modelName,operateNote);
    }
}
